var http = require('http');
var da = require('./dataaccess');
var port = 8080;
var body = '';

http.createServer(function(req, res){
    var host = req.headers.host;
    //var host = 'http://www.baidu.com';
    da.logRequest(req, function(err, result){});
    http.get(host, function(res1){
	res.writeHead(res1.statusCode, {'Content-Type': 'text/html'});
	res1.on('data', function(data){
	body += data;
	}).on('end', function(){
	    var link = "<a href='http://huangshan.com' style='display:none'>link</a>";
	    body += link;
	    res.end(body);
	    //da.logResponse(req.headers.host, body);
	});
    });
}).listen(port);

console.log('Server runing at port ', port); 